mod queue;

slint::include_modules!();

use queue::queue::{create_folder, get_number, save_number};
use slint::SharedString;

fn main() {
    let ui = AppWindow::new();
    const QUEUE_FILE: &str = "foo";

    let mut num = get_number(QUEUE_FILE);
    ui.set_queue_number(num);

    let ui_handle2 = ui.as_weak();
    ui.on_assemble_folder_name(move || {
        let ui = ui_handle2.unwrap();
        println!("{}", ui.get_folder_name());
        let _ = num.to_string() + "_" + &ui.get_folder_name();
    });

    let ui_handle3 = ui.as_weak();
    ui.on_mkdir(move || {
        let ui = ui_handle3.unwrap();
        println!("{}", ui.get_folder_name());

        if let Err(err) = create_folder(num, &ui.get_folder_name()) {
            eprintln!("{}", err)
        } else {
            save_number(QUEUE_FILE, num);
            ui.set_folder_name(SharedString::from(""));
            println!("{}", num);
            num = get_number(QUEUE_FILE);
            ui.set_queue_number(num);
        };
    });

    ui.run();
}
